package com.qf.aop;


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 *
 * 环绕通知
 * @author lixu
 */
public class MyMethodInterceptor implements MethodInterceptor {
    /**
     * 环绕 通知
     *   包含 ：前置
     *         后置
     *         异常
     *
     * @param invocation the method invocation joinpoint
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        //前置 辅助代码
        System.out.println("==1:发布房屋信息");
        System.out.println("==2:带租户看房");
        Object result = null;
        try {
            //回到核心代码
            result = invocation.proceed();//
        } catch (Throwable e) {
            //异常通知代码
            System.out.println("我异常了。我是异常通知 ！！！");
            return result;
        }
        //后置辅助代码
        System.out.println("==5:维修");
        System.out.println("==6:转租");
        //将核心代码的返回值 返回到浏览器
        return result;
    }
}
